<template>
  <div class="index-wrapper">
    <div class="header-wrapper">
      <div class="header">
        <div class="nav-bar">
          <div class="nav-bar-left-part">
            <div class="logo">
              <img src="@/assets/logo/logo.png" alt="" style="width: 42px; height: 42px;">
              <span style="font-size: 20px;">CoolColdCode</span>
            </div>
            <ul class="nav-item-list">
              <li class="active">首页</li>
              <li @click="toMsgBoarderPage">留言板</li>
              <li @click="toSearchPage">搜索</li>
              <li @click="showInfo">更多</li>
            </ul>
          </div>
          <div class="nav-bar-right-part">
            <div class="actions">
              <div class="search-part">
                <div class="search-box">
                  <input type="text" class="search-box-input" placeholder="搜索内容" @focus="searchBoxFocus = true" @blur="searchBoxFocus = false">
                  <a-icon class="search-box-icon" type="search"/>
                </div>
                <div class="suggestion-button" :class="{hide: searchBoxFocus}">
                  <span @click="showInfo"> 意见反馈 </span>
                </div>
              </div>
              <div class="user-action-part">
                <div v-if="userInfo === null" class="login-button" @click="toLoginPage">登录</div>
                <div v-else class="info-wrapper" @click="toProfilePage">
                  <a-avatar v-if="userInfo['avatar'] === null" icon="user" />
                  <a-avatar v-else :src="userInfo['avatar']" />
                  <span class="nickname">{{userInfo['nickname']}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="content-wrapper">
      <div class="content">
        <div class="content-logo">
          <img src="@/assets/logo/content-logo.png" alt="" style="width: 400px; height: 400px;">
        </div>
        <div class="content-start-button">
          <div class="start-button" @click="toLoginPage">
          </div>
        </div>
        <div class="content-typing">
          <span class="text-typing">
            岁月漫长，然而值得期待
          </span>
        </div>
      </div>
    </div>
    <div class="footer-wrapper">
      <span>
        &copy; Copyright 2021-2021 www.coolcoldcode.com 版权所有
      </span>
    </div>
  </div>
</template>

<script>
export default {
  name: "index",
  data: _ => ({
    searchBoxFocus: false,
    userInfo: null,
  }),
  methods: {
    toProfilePage () {
      this.$router.push('/profile')
    },
    toMsgBoarderPage () {
      this.$router.push('/msgboard')
    },
    toLoginPage () {
      this.$router.push('/login')
    },
    toSearchPage() {
      this.$router.push('/search')
    },
    showInfo () {
      this.$message.info('创意构想中，敬请期待')
    },
    loadUserInfo () {
      if (localStorage.getItem('userInfo')) {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
      } 
    },
  },
  mounted() {
    this.loadUserInfo()
  },
}
</script>

<style scoped lang="less">
.index-wrapper {
  height: 100vh;
  .header-wrapper {
    height: 55px;
    min-width: 1260px;
    border-bottom: 1px solid #ccc;
    .header {
      margin: 0 auto;
      width: 1260px;
      height: 55px;
      .nav-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 55px;
        .nav-bar-left-part {
          display: flex;
          justify-content: left;
          align-items: center;
          height: 55px;
          .logo {
            margin-left: 12px;
            display: flex;
            justify-content: center;
            align-items: center;
            span {
              margin-left: 12px;
              user-select: none;
            }
          }
          .nav-item-list {
            margin-left: 20px;
            height: 55px;
            display: flex;
            justify-content: space-around;
            align-items: center;
            li {
              font-size: 16px;
              width: 80px;
              user-select: none;
              text-align: center;
              cursor: pointer;
              &:hover {
                color: #1e80ff;
              }
              &.active {
                color: #1e80ff;
              }
            }
          }
        }
        .nav-bar-right-part {
          .actions {
            display: flex;
            justify-content: left;
            align-items: center;
            .search-part {
              display: flex;
              justify-content: left;
              align-items: center;
              width: 400px;
              
              .search-box {
                flex: 1;
                position: relative;
                background-color: skyblue;;
                
                .search-box-input {
                  width: 100%;
                  outline: none;
                  padding: 4px 12px;
                  color: #666;
                  height: 32px;
                  border: 1px solid transparent;
                  background-color: #eee;
                  transition: .3s;
                  &:focus {
                    border: 1px solid #1e80ff;
                  }
                }
                .search-box-icon {
                  position: absolute;
                  top: 8px;
                  right: 5px;
                  color: #666;
                }
              }

              .suggestion-button {
                margin-left: 10px;
                background-color: #e8f3ff;
                color: #1e80ff;
                width: 100px;
                height: 32px;
                display: flex;
                justify-content: center;
                align-items: center;
                transition: .3s;
                cursor: pointer;
                span {
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  user-select: none;
                }
                overflow: hidden;
                text-overflow: ellipsis;
                &.hide {
                  visibility: hidden;
                  margin-left: 0;
                  width: 0;
                }
              }
            }
            .user-action-part {
              margin-left: 14px;
              .login-button {
                display: flex;
                justify-content: center;
                border-radius: 2px;
                align-items: center;
                width: 100px;
                height: 32px;
                background-color: #1e80ff;
                color: white;
                user-select: none;
                cursor: pointer;
              }
              .info-wrapper {
                display: flex;
                justify-content: left;
                align-items: center;
                cursor: pointer;
                .nickname {
                  margin-left: 10px;
                  user-select: none;
                  color: #666;
                  font-size: 14px;
                }
              }
            }
          }
        }
      }
    }
  }
  .content-wrapper {
    min-width: 1260px;
    display: flex;
    justify-content: center;
    .content {
      width: 1260px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: left;
      
      .content-logo {
      }
      
      .content-typing {
        margin-top: 80px;
        font-size: 32px;
        width: 11em;
        white-space: nowrap;
        box-sizing: content-box;
        border-right: .2em solid transparent;
        animation: content-typing 11s steps(11, end) infinite, content-blink-caret .5s step-end infinite;
        overflow: hidden;
      }

      .content-start-button {
        height: 60px;
        width: 300px;
        display: flex;
        align-items: center;
        justify-content: center;
        .start-button {
          position: relative;
          transition: .5s;
          &:before {
            content: '开始';
            display: flex;
            width: 100px;
            height: 40px;
            font-size: 24px;
            color: #2c3e50;
            border: 1px solid transparent;
            justify-content: center;
            align-items: center;
            user-select: none;
            cursor: pointer;
            border-radius: 20px;
            transition: .5s;
            white-space: nowrap;
            overflow: hidden;
            transform-origin: 50% 50%;
            text-overflow: ellipsis;
          }
          &:hover {
            &:before {
              animation: start-button-show 1s ease;
              border: 1px solid #1e80ff;
              color: #1e80ff;
              width: 200px;
              height: 60px;
              border-radius: 30px;
              content: '尝试新鲜事';
            }
          }
        }
      }
      
    }
  }
  .footer-wrapper {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100vw;
    height: 60px;
    border-top: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

@keyframes start-button-show {
  from {
    color: transparent;
  }
  to {
    color: #1e80ff;
  }
}

@keyframes content-typing {
  from, to { 
    width: 0;
  }
  33% {
    width: 11em;
  }
  66% {
    width: 11em;
  }
}

@keyframes content-blink-caret {
  from, to {
    box-shadow: 1px 0 0 0 transparent;
  }
  50% {
    box-shadow: 1px 0 0 0;
  }
}
</style>